package puzzle.common.point;

public enum Direction {
	N(0, -1), NE(1, -1), E(1, 0), SE(1, 1), S(0, 1), SW(-1, 1), W(-1, 0), NW(-1, -1);

	public static final Direction[] CLOCKWISE4 = new Direction[] { N, E, S, W };
	
	public static final Direction[] CLOCKWISE8 = values();

	public final Vct v;

	private Direction(int dx, int dy) {
		v = new Vct(dx, dy);
	}

	public static Direction quad(Vct v) {
		if (v.dx >= 0 && v.dy < 0) {
			return N;
		} else if (v.dx <= 0 && v.dy > 0) {
			return S;
		} else if (v.dy >= 0 && v.dx > 0) {
			return E;
		} else if (v.dy <= 0 && v.dx < 0) {
			return W;
		} else {
			assert v.dx == 0 && v.dy == 0;
			return null;
		}
	}
	
	public Direction inv() {
		return values()[(ordinal() + 4) & 7];
	}

	public Direction rrot() {
		return values()[(ordinal() + 2) & 7];
	}

	public Direction lrot() {
		return values()[(ordinal() - 2) & 7];
	}
}
